package top.kaoshanji.q1ch05a.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/4/24 10:53
 */
@Configuration
public class DataConfig {

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:5500/Code-Learn-can2024122433-version1?useUnicode-true&serverTimezone=UTC&allowpublicKeyRetrieval-true&characterEncoding-utf8&usessL-false");
        dataSource.setUsername("xxxppp");
        dataSource.setPassword("P!14.b@1k3");

        return dataSource;
    }

    @Bean
    public JdbcOperations jdbcOperations(DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

}
